home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / prefIM.js < prev    next >
Encoding:
Text File  |  2002-06-25  |  73.0 KB  |  2,352 lines

  1. var IMServiceClass = Components.classes['@netscape.com/aim/IMManager;1'];
  2. var pIIMManager  = IMServiceClass.getService(Components.interfaces.nsIIMManager)
  3. var lastRadio = null;
  4. var lastViewRadio = null;
  5. var allEnums = Components.interfaces.nsAimPrivacyModes;
  6. var stateEnums = Components.interfaces.nsAimOnlineStates;
  7. var globalPrivacyObject = pIIMManager.QueryInterface(Components.interfaces.nsIAimPrivacy);
  8. var MozPreferences = Components.classes['@mozilla.org/preferences-service;1'];
  9. MozPreferences = MozPreferences.getService();
  10. MozPreferences = MozPreferences.QueryInterface(Components.interfaces.nsIPrefBranch);
  11.  
  12. //connection panel
  13. var connLinks = new Object();
  14. connLinks.ConnectionName = "";
  15. connLinks.SessionType    = "";
  16. connLinks.Host           = "";
  17. connLinks.Port           = "";
  18. connLinks.ProxyHost      = "";
  19. connLinks.ProxyPort      = "";
  20. connLinks.ProxyUser      = "";
  21. connLinks.ProxyPassword  = "";
  22. connLinks.ProxyProtocol  = "";
  23. connLinks.IsProxy        = false;
  24. connLinks.ConnectionType = 0;
  25.  
  26. //end connection panel
  27.  
  28. function getString(name)
  29. {
  30.     if (aimStringBundle()){
  31.                 return aimStringBundle().GetStringFromName(name);
  32.         }
  33.         else{
  34.             return "";
  35.         }
  36. }
  37.  
  38. function EditAwayMessageOnLoad()
  39. {
  40.     // poke in the arguments 
  41.  
  42.     var nameItem = document.getElementById("awayMessageName");
  43.     var textItem = document.getElementById("awayMessageText");
  44.  
  45.     nameItem.value = window.arguments[1];
  46.     textItem.value = window.arguments[2];
  47.     nameItem.focus();
  48.  
  49.     // construct some of the static labels here; had problems placing
  50.     // '%' into an DTD ENTITY
  51.  
  52.     var labelItem = document.getElementById("editAwayMessageSpecial1");
  53.     var stringItem = getString( "editAwayMessageSpecial1" );
  54.     labelItem.setAttribute( "value", stringItem );
  55.     labelItem = document.getElementById("editAwayMessageSpecial2");
  56.     stringItem = getString( "editAwayMessageSpecial2" );
  57.     labelItem.setAttribute( "value", stringItem );
  58.     labelItem = document.getElementById("editAwayMessageSpecial3");
  59.     stringItem = getString( "editAwayMessageSpecial3" );
  60.     labelItem.setAttribute( "value", stringItem );
  61.     labelItem = document.getElementById("editAwayMessageSpecial4");
  62.     stringItem = getString( "editAwayMessageSpecial4" );
  63.     labelItem.setAttribute( "value", stringItem );
  64.  
  65.     // set the OK, Cancel callbacks
  66.  
  67.     if ( nameItem.value == "" ) 
  68.         doSetOKCancel(AddAwayMessageOnOK, 0);
  69.     else    
  70.         doSetOKCancel(EditAwayMessageOnOK, 0);
  71. }
  72.  
  73. function PrefIMAwayOnLoad()
  74. {
  75.    if( (false == IsSignedOn()) || (isIcq() == true) ) {
  76.       var str = getString( "away.entermsg" );        
  77.         DisableAwayUI();
  78.         alert( str );
  79.     parent.hPrefWindow.registerOKCallbackFunc(DiscardAwayChanges);
  80.     }
  81.   else {
  82.  
  83.     GetRDFService();
  84.     sidebar_file = GetRdfFileUrl("default-messages.rdf", "dm.rdf");  
  85.     datasource = RDF.GetDataSource(sidebar_file);
  86.     var tree = document.getElementById("AwayMessages");
  87.     tree.database.AddDataSource(datasource);
  88.     tree.setAttribute('ref', tree.getAttribute('ref'));
  89.     
  90.   }
  91.  
  92. }
  93.  
  94. /*
  95.  * Function:  PrefIMStyleOnload ()
  96.  * Arguments:
  97.  * Return:  None
  98.  * Description:  This function intializes the pref-IM_style.xul panel
  99.  *               In paticular the text and background color widgets
  100.  *               are filled in and the Special Text Styles are turned
  101.  *               on or off depending on the pref.
  102.  *
  103.  * Author: jelwell@netscape.com
  104. */
  105. function PrefIMStyleOnload()
  106. {
  107.   var textData = document.getElementById("textColorData");
  108.   var backgroundData = document.getElementById("backgroundColorData");
  109.   var customTextColor = textData.getAttribute("value");
  110.   var customBackgroundColor = backgroundData.getAttribute("value");
  111.  
  112.   if ( !customBackgroundColor || customBackgroundColor == "")
  113.     customBackgroundColor = "#FFFFFF";
  114.   if ( !customTextColor || customTextColor == "")
  115.     customTextColor = "#000000";
  116.   setColorWell("textCW", customTextColor);
  117.   setColorWell("backgroundCW", customBackgroundColor);
  118.  
  119.   textData.setAttribute("value", customTextColor); 
  120.   backgroundData.setAttribute("value", customBackgroundColor); 
  121.  
  122.   SwapSpecialStyles();
  123. }
  124.  
  125. /*
  126.  * Function:  SwapSpecialStyles()
  127.  * Arguments:
  128.  * Return:  None
  129.  * Description:  This function is used to toggle the special
  130.  *               text style checkboxes, on and off depending
  131.  *               on the pref and current setting.
  132.  *
  133.  * Author: jelwell@netscape.com
  134. */
  135. function SwapSpecialStyles()
  136. {
  137.   if (document.getElementById("textstyles").getAttribute("value") == "1")
  138.   {
  139.     document.getElementById("bold").removeAttribute("disabled");
  140.     document.getElementById("italics").removeAttribute("disabled");
  141.     document.getElementById("underline").removeAttribute("disabled");
  142.     
  143.   }
  144.   else
  145.   {
  146.     document.getElementById("bold").setAttribute("disabled", "true");
  147.     document.getElementById("italics").setAttribute("disabled", "true");
  148.     document.getElementById("underline").setAttribute("disabled", "true");
  149.     
  150.   }
  151. }
  152.  
  153. /*
  154.  * Function:  GetColorAndUpdate(ColorWellID)
  155.  * Arguments:
  156.  *    ColorWellID -- id of the color spacer inside the button.
  157.  * Return:  None
  158.  * Description:  This function is used to change the background
  159.  *               color of the spacer based on prefs.
  160.  *
  161.  * Author: jelwell@netscape.com
  162. */
  163. function GetColorAndUpdate(ColorWellID)
  164. {
  165.   var colorObj = new Object;
  166.   var colorWell = document.getElementById(ColorWellID);
  167.   var customTextColor = document.getElementById("textColorData").getAttribute("value"); 
  168.   var customBackgroundColor = document.getElementById("backgroundColorData").getAttribute("value"); 
  169.   if (!colorWell) return;
  170.  
  171.   // Don't allow a blank color, i.e., using the "default"
  172.   colorObj.NoDefault = true;
  173.  
  174.   switch( ColorWellID )
  175.   {
  176.     case "textCW":
  177.       colorObj.Type = "Text";
  178.       colorObj.TextColor = customTextColor;
  179.       break;
  180.     case "backgroundCW":
  181.       colorObj.Type = "Page";
  182.       colorObj.PageColor = customBackgroundColor;
  183.       break;
  184.   }
  185.  
  186.   window.openDialog("chrome://editor/content/EdColorPicker.xul", "_blank", "chrome,close,titlebar,modal", "", colorObj);
  187.  
  188.   // User canceled the dialog
  189.   if (colorObj.Cancel)
  190.     return;
  191.  
  192.   var color = "";
  193.   switch( ColorWellID )
  194.   {
  195.     case "textCW":
  196.       color = customTextColor = colorObj.TextColor;
  197.       document.getElementById("textColorData").setAttribute("value", color); 
  198.       break;
  199.     case "backgroundCW":
  200.       color = customBackgroundColor = colorObj.BackgroundColor;
  201.       document.getElementById("backgroundColorData").setAttribute("value", color);
  202.       break;
  203.   }
  204.   setColorWell(ColorWellID, color); 
  205. //  SetColorPreview(ColorWellID, color);
  206. }
  207.  
  208.  
  209. // XXXVISHy 
  210. // Add a user to the allow or deny list. top.addMode defines which list
  211.  
  212. function GetUserAdd()
  213. {
  214.         var fldUserName = top.document.getElementById("fldUserName");
  215.         var pIAimPrivacy = aimPrivacy();
  216.         var name = fldUserName.value;
  217.         if ( name && name != "" ) {
  218.            if ( top.addMode == "Allow" ) {
  219.               pIAimPrivacy.AllowListAdd( name );
  220.            }
  221.         else if ( top.addMode == "Deny" ) {
  222.             pIAimPrivacy.DenyListAdd( name );
  223.         }
  224.         //pIAimPrivacy.UpdateStorage();
  225.            top.opener.updateListBoxSelection(top.addMode);
  226.            top.window.close();
  227.         }
  228. }
  229.  
  230.  
  231.  
  232. function updateListBoxSelection(mode){
  233.    var targetListBox = document.getElementById(mode);
  234.    var targetListBoxSelectedCount = targetListBox.selectedCount
  235.    var targetListBoxRows = targetListBox.listBoxObject.getRowCount();
  236.    if(targetListBoxRows >0 && targetListBoxSelectedCount <1){
  237.       targetListBox.selectedIndex=0;
  238.    }
  239.  
  240. }
  241.  
  242. /* 
  243.  * Name: StandardURL
  244.  *
  245.  * Arguments: URI string, e.g., chrome://foo/bar
  246.  *
  247.  * Description: obtains an instance of nsIURL and sets the spec to the passed
  248.  * uri. Returns the nsIURL instance.
  249.  *
  250.  */
  251.  
  252. function StandardURL(s) {
  253.     var clazz = Components.classes["@mozilla.org/network/standard-url;1"];
  254.     var iface = Components.interfaces.nsIURL;
  255.     var obj = clazz.createInstance(iface);
  256.     obj.spec = s;
  257.     return obj;
  258.  
  259. /* 
  260.  * Name: Sound
  261.  *
  262.  * Arguments: none 
  263.  *
  264.  * Description: Creates and returns an instance of nsISound
  265.  *
  266.  */
  267.  
  268. function Sound() {
  269.     var clazz = Components.classes["@mozilla.org/sound;1"];
  270.     var iface = Components.interfaces.nsISound;
  271.     var obj = clazz.createInstance(iface);
  272.     return obj;
  273. }
  274.  
  275. /* 
  276.  * Name: PlaySound
  277.  *
  278.  * Arguments: chrome URI to a sound file
  279.  *
  280.  * Description: Called by onclick handler for speaker titled buttons in
  281.  * the sound preferences panel for IM.
  282.  *
  283.  */
  284.  
  285. function PlaySound( myURIPref )
  286. {
  287.     var sound = new Sound();
  288.     var myURI;
  289.  
  290.     try {
  291.         myURI = aimPrefsManager().GetCharPref( myURIPref , null, false );
  292.     }
  293.     catch(e) {
  294.         try {
  295.             myURI = aimPrefsManager().GetCharPref( myURIPref , null, true); // get the global one if the per screen name doesnt work
  296.         }
  297.         catch(e) {
  298.             return;
  299.         }         
  300.     }        
  301.  
  302.     var uri = new StandardURL(myURI);
  303.     if ( sound != undefined && sound != null && uri != undefined && uri != null ) {
  304.         try {
  305.             sound.play( uri );
  306.         }
  307.         catch( e ) {
  308.             // device may not support sound, so ignore
  309.         }
  310.     }    
  311. }
  312.  
  313. /* away messages */
  314.  
  315. var datasource = null;
  316. var RDF = null;
  317. var awayMessages = null;
  318.  
  319. function
  320. GetRDFService()
  321. {
  322.     if ( RDF == null ) {
  323.         RDF=aimRDF();
  324.     }
  325. }
  326.  
  327. function
  328. RemoveTarget( msgName )
  329. {
  330.     GetRDFService();
  331.  
  332.     var messages_file = GetRdfFileUrl("default-messages.rdf", "dm.rdf"); 
  333.     var datasource = RDF.GetDataSource(messages_file);
  334.  
  335.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  336.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  337.       container.Init(datasource, RDF.GetResource("NC:AIM/AwayMessageBag"));
  338.  
  339.     var elements = container.GetElements();
  340.     var target, node;
  341.     var nameResource = 
  342.                 RDF.GetResource("http://home.netscape.com/NC-rdf#MsgName");
  343.     while ( elements.hasMoreElements() ) {
  344.         node = elements.getNext();
  345.         if ( node ) 
  346.             target = datasource.GetTarget( node, nameResource, 
  347.                 true );
  348.         if ( target ) 
  349.             target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
  350.         if ( target && target.Value == msgName ) {
  351.             container.RemoveElement( node, true );
  352.             datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  353.         }
  354.     }
  355.     return null;
  356. }
  357.  
  358. function
  359. SetAwayMessageTarget( msgName, msgText )
  360. {
  361.     GetRDFService();
  362.  
  363.     var messages_file = GetRdfFileUrl("default-messages.rdf", "dm.rdf"); 
  364.     var datasource = RDF.GetDataSource(messages_file);
  365.  
  366.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  367.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  368.       container.Init(datasource, RDF.GetResource("NC:AIM/AwayMessageBag"));
  369.  
  370.     var elements = container.GetElements();
  371.     var nametarget, texttarget, node;
  372.     var nameResource = 
  373.                 RDF.GetResource("http://home.netscape.com/NC-rdf#MsgName");
  374.     var textResource = 
  375.                 RDF.GetResource("http://home.netscape.com/NC-rdf#MsgText");
  376.     while ( elements.hasMoreElements() ) {
  377.         node = elements.getNext();
  378.         if ( node ) 
  379.             nametarget = datasource.GetTarget( node, nameResource, 
  380.                 true );
  381.         if ( nametarget ) 
  382.             nametarget = nametarget.QueryInterface(Components.interfaces.nsIRDFLiteral);
  383.         if ( nametarget && nametarget.Value == msgName ) {
  384.             texttarget = datasource.GetTarget( node, textResource, 
  385.                 true );
  386.             if ( texttarget ) 
  387.                 texttarget = texttarget.QueryInterface(Components.interfaces.nsIRDFLiteral);
  388.             if ( texttarget ) {
  389.                 var newText = RDF.GetLiteral(msgText);
  390.                 datasource.Change( node, textResource,
  391.                     texttarget, newText);
  392.                 datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  393.             }
  394.             break;
  395.         }
  396.     }
  397. }
  398.  
  399. //XXXVISHY - two 
  400.  
  401. function modeToRadio(mode)
  402. {
  403.  
  404.     switch(mode) {
  405.     case allEnums.AllowAll:
  406.     dump ("allEnums.AllowAll\n" );
  407.         return document.getElementById("aim_privacy_contact_allowallusers"); 
  408.         break;
  409.     case allEnums.AllowBuddies:
  410.     dump ("allEnums.AllowBuddies\n" );
  411.         return document.getElementById("aim_privacy_contact_allowbuddylistusers"); 
  412.         break;
  413.     case allEnums.AllowList:
  414.     dump ("allEnums.AllowOnlyList\n" );
  415.         return document.getElementById("aim_privacy_contact_allowonlylist"); 
  416.         break;
  417.     case allEnums.DenyAll:
  418.     dump ("allEnums.DenyAll\n" );
  419.       
  420.         return document.getElementById("aim_privacy_contact_blockallusers"); 
  421.         break;
  422.     case allEnums.DenyList:
  423.     dump ("allEnums.DenyList\n" );
  424.         return document.getElementById("aim_privacy_contact_blocklistusers"); 
  425.         break;
  426.     default:
  427.         dump("Bad privacy mode\n");
  428.         return document.getElementById("aim_privacy_contact_allowallusers"); 
  429.         break;
  430.     }
  431. }
  432.  
  433. function privacyModeRadio(mode)
  434. {
  435.   dump("privacyModeRadio\n");
  436.  
  437.   // this should not be needed, but believe me dont remove it 
  438.   // otherwise radio UI can show two things selected ;-)
  439.   lastRadio.checked = false;
  440.   lastRadio = modeToRadio(mode);
  441.   dump ("lastRadio is " + lastRadio + "\n");
  442.   lastRadio.checked = true;
  443.   parent.lastPrivacyMode = mode;
  444.  
  445.   dump ("lastPrivacyMode is " + parent.lastPrivacyMode + "\n");
  446. }
  447.  
  448. function privacyChatInvites(value)
  449. {
  450.   parent.lastChatInvites = value;
  451. }
  452.  
  453. function privacyIdle(value)
  454. {
  455.   parent.lastIdle = value;
  456. }
  457.  
  458.  
  459. function viewToRadio(view)
  460. {
  461.   dump("in function viewToRadio\n" + view);
  462.  
  463.     switch(view) {
  464.     case '1':
  465.         return document.getElementById("nodisclosure"); 
  466.         break;
  467.     case '2':
  468.         return document.getElementById("limiteddisclosure"); 
  469.         break;
  470.     case '3':
  471.         return document.getElementById("fulldisclosure"); 
  472.         break;
  473.     default:
  474.         dump("Bad privacy view\n");
  475.         return document.getElementById("nodisclosure"); 
  476.         break;
  477.     }
  478. }
  479.  
  480. function privacyViewRadio(view)
  481. {
  482.   dump("privacyModeRadio\n");
  483.  
  484.   // this should not be needed, but believe me dont remove it 
  485.   // otherwise radio UI can show two things selected ;-)
  486.   //lastViewRadio.checked = false;
  487.   //lastViewRadio = viewToRadio(view);
  488.   dump ("lastViewRadio is " + lastViewRadio + "\n");
  489.   //lastViewRadio.checked = true;
  490.   parent.lastPrivacyView = view;
  491.  
  492.   dump ("lastPrivacyView is " + parent.lastPrivacyView + "\n");
  493. }
  494.  
  495. // onload handler for privacy panel. grab the privacy mode enums, and register
  496. // AssertChanges with prefwindow so we get called on OK presses.
  497.  
  498. AdminCallback = new Object();
  499. AdminCallback.OnRequestInfoComplete = function(type,info)
  500. {
  501.     dump("On RequestInfoComplete\n");
  502.  
  503.     switch (type) { 
  504.     case Components.interfaces.nsIAimAdminInfo.RegistrationStatusPreference:
  505.         dump("info is " + info + "\n");
  506.         parent.lastPrivacyView = info;
  507.  
  508.         dump("Got the aim privacy view\n");
  509.         lastViewRadio = viewToRadio(parent.lastPrivacyView);
  510.     
  511.         if ( lastViewRadio != undefined && lastViewRadio != null) {
  512.             var privacyViewElement = document.getElementById("privacyView");
  513.             privacyViewElement.selectedItem = lastViewRadio;
  514.         }
  515.         break;
  516.     default:
  517.         break;
  518.     }
  519. }
  520. AdminCallback.OnRequestInfoError = function(pErrMsg)
  521. {
  522.     dump("OnRequestInfoError\n");
  523. }
  524.  
  525. adminGetterCallback = new Object();
  526.  
  527. adminGetterCallback.ExecuteIfReady = function()
  528. {
  529.     dump("about to get the disclosure level\n");
  530.     aimAdminManager().RequestInfoRegistrationStatusPreference(AdminCallback);
  531. }
  532.  
  533. function DisablePrivacyUI()
  534. {
  535.         var el = document.getElementById("aim_privacy_contact_allowallusers");
  536.         if ( el )
  537.             el.setAttribute( "disabled", "true" );
  538.         el = document.getElementById("aim_privacy_contact_allowbuddylistusers");
  539.         if ( el )
  540.             el.setAttribute( "disabled", "true" );
  541.         el = document.getElementById("aim_privacy_contact_allowonlylist");
  542.         if ( el )
  543.             el.setAttribute( "disabled", "true" );
  544.         el = document.getElementById("aim_privacy_contact_blockallusers");
  545.         if ( el )
  546.             el.setAttribute( "disabled", "true" );
  547.         el = document.getElementById("aim_privacy_contact_blocklistusers");
  548.         if ( el )
  549.             el.setAttribute( "disabled", "true" );
  550.         el = document.getElementById("button1");
  551.         if ( el )
  552.             el.setAttribute( "disabled", "true" );
  553.         el = document.getElementById("button2");
  554.         if ( el )
  555.             el.setAttribute( "disabled", "true" );
  556.         el = document.getElementById("button3");
  557.         if ( el )
  558.             el.setAttribute( "disabled", "true" );
  559.         el = document.getElementById("button4");
  560.         if ( el )
  561.             el.setAttribute( "disabled", "true" );
  562.         el = document.getElementById("chatInvites");
  563.         if ( el )
  564.             el.setAttribute( "disabled", "true" );
  565. /*        el = document.getElementById("idleTime");
  566.         if ( el )
  567.             el.setAttribute( "disabled", "true" );
  568. */
  569.         el = document.getElementById("privacyView");
  570.         if ( el )
  571.             el.setAttribute( "disabled", "true" );
  572.         el = document.getElementById("fulldisclosure");
  573.         if ( el )
  574.             el.setAttribute( "disabled", "true" );
  575.         el = document.getElementById("limiteddisclosure");
  576.         if ( el )
  577.             el.setAttribute( "disabled", "true" );
  578.         el = document.getElementById("nodisclosure");
  579.         if ( el )
  580.             el.setAttribute( "disabled", "true" );
  581. }
  582.  
  583. function DiscardPrivacyChanges()
  584. {
  585.  
  586.     var IMServiceClass = Components.classes['@netscape.com/aim/IMManager;1'];
  587.     var pIIMManager  = IMServiceClass.getService(Components.interfaces.nsIIMManager);
  588.     var pIAimString = pIIMManager.QueryInterface(Components.interfaces.nsIStringBundle);
  589.     
  590.     if ( pIAimString == undefined || pIAimString == null )
  591.         return;
  592.  
  593.     var str = pIAimString.GetStringFromName( "privacy.exitmsg" );
  594.     if (str == undefined || str ==null)
  595.         return;
  596.     
  597.     alert( str );
  598. }
  599.  
  600. function IsSignedOn()
  601. {
  602.     var state = aimSession().CurrentState;
  603. dump( "state is " + state + " \n" );
  604.  
  605.     if ( state == stateEnums.Online || state == stateEnums.OnlineAway )
  606.         return true;
  607.     return false;
  608. }
  609.  
  610. function PrefIMPrivacyOnLoad()
  611. {
  612.     dump("PrefIMPrivacyOnLoad\n");
  613.     if ( (false == IsSignedOn()) || (isIcq() == true) ) {
  614.         var str = getString( "privacy.entermsg" );        
  615.         DisablePrivacyUI();
  616.         alert( str );
  617.         parent.hPrefWindow.registerOKCallbackFunc( DiscardPrivacyChanges );
  618.     }
  619.     else { 
  620.         parent.hPrefWindow.registerOKCallbackFunc( AssertPrivacyChanges );
  621.  
  622.  
  623.     //var sessionType=aimSession.getSessionType();
  624.     var sessionType =aimPrefsManager().GetIntPref("aim.session.sessiontype", null, false);
  625.     if( sessionType == 0) {
  626.         var tree = document.getElementById("Allow");
  627.         tree.database.AddDataSource(aimRDF().GetDataSource("rdf:AIM"));
  628.         tree.setAttribute('ref', tree.getAttribute('ref'));
  629.         var tree = document.getElementById("Deny");
  630.         tree.database.AddDataSource(aimRDF().GetDataSource("rdf:AIM"));
  631.         tree.setAttribute('ref', tree.getAttribute('ref'));
  632.     }
  633.     }
  634.     var priv = aimPrivacy();
  635.     // do it only the first time!
  636.     if (parent.lastPrivacyMode == undefined)
  637.         parent.lastPrivacyMode = priv.PrivacyMode;
  638.  
  639.     dump("Got the aim privacy mode\n");
  640.     lastRadio = modeToRadio(parent.lastPrivacyMode);
  641.  
  642.     if ( lastRadio != undefined && lastRadio != null)
  643.         lastRadio.setAttribute("selected","true");
  644.  
  645.     if ( parent.lastChatInvites != undefined && parent.lastChatInvites != null) {
  646.                 var checkbox = document.getElementById("chatInvites");
  647.                 if ( checkbox != undefined && checkbox != null ) {
  648.                         checkbox.setAttribute("selected",parent.lastChatInvites);
  649.                 }
  650.         }
  651.  
  652.     dump("set the radio.selected property\n");
  653.         //aimPreferenceOnload();
  654.     //dump("did the per screen name munging\n");
  655.  
  656.     var loggedin = true;
  657.  
  658.     if (loggedin && (parent.lastPrivacyView == undefined))
  659.     {
  660.         aimAdminManager().ExecuteIfReady(adminGetterCallback);
  661.     }
  662.   var feedbag = aimFeedbagManager();
  663.   var prefmask = feedbag.GetBuddyPrefs();
  664.   if (prefmask & Components.interfaces.nsAimBuddyPrefs.DiscloseIdleTime)
  665.   {
  666.     document.getElementById("idle").checked = true;
  667.     parent.lastIdle = true;
  668.   }
  669.   else
  670.   {
  671.     parent.lastIdle = false;
  672.   }
  673.     updateListBoxSelection("Allow");
  674.     updateListBoxSelection("Deny");
  675. }
  676.  
  677. function PrefIMPrivacyOnUnload() 
  678. {
  679.     // nothing for now
  680. }
  681.  
  682. // grab a screenname from the user.
  683.  
  684. function PostGetUserDlg( which )
  685.     openDialog("chrome://aim/content/pref-IM_getuser.xul", "", 
  686.         "modal=yes,chrome", which);
  687. }
  688.  
  689. // delete the screenname entered by the user from the allow or deny list.
  690. // "which" indicates which list to purge from
  691.  
  692. function DeleteFromList( which )
  693. {
  694.     var listbox = document.getElementById(which);
  695.     var pIAimPrivacy = aimPrivacy();
  696.     var selectedUser;
  697.     
  698.         
  699.     for (var i = 0; i <= listbox.selectedItems.length; i++) {
  700.       selectedUser = listbox.selectedItems[i].getAttribute("label");
  701.       if ( which == "Allow" ) {
  702.           pIAimPrivacy.AllowListRemove( selectedUser );
  703.           }
  704.       else if ( which == "Deny" ) {
  705.           pIAimPrivacy.DenyListRemove( selectedUser );
  706.           }
  707.       updateListBoxSelection(which);
  708.       break;
  709.     }
  710. }
  711.  
  712. // onload handler for the dialog used to get a screenname from the user
  713.  
  714. function GetUserOnLoad()
  715. {
  716.         doSetOKCancel(GetUserAdd, 0);
  717.     top.addMode = window.arguments[0];
  718.     document.getElementById("fldUserName").focus();
  719. }
  720.  
  721. // called when OK button is pressed in privacy mode preferences panel. Figure
  722. // out what changed, communicate this to AIM Glue backend
  723.  
  724. function AssertPrivacyChanges()
  725. {
  726.     // We cannot use global variables as this is called in the
  727.     // context of the Parent window much later!!
  728.     dump("Calling function prefIM.js AssertChanges\n");
  729.     var IMServiceClass = Components.classes['@netscape.com/aim/IMManager;1'];
  730.     var pIIMManager  = IMServiceClass.getService(Components.interfaces.nsIIMManager)
  731.     var lastRadio = null;
  732.     var allEnums = Components.interfaces.nsAimPrivacyModes;
  733.     var pIAimPrivacy = pIIMManager.QueryInterface(Components.interfaces.nsIAimPrivacy)
  734.     
  735.     if ( pIAimPrivacy == undefined || pIAimPrivacy == null )
  736.         return;
  737.  
  738.     // This has been simplified and made correct
  739.     pIAimPrivacy.PrivacyMode = parent.lastPrivacyMode;
  740.     var tvalues = false;
  741.  
  742.     dump ("saved privacy mode in AIM as " + parent.lastPrivacyMode + "\n");
  743.     
  744.     var pAimAdmin = pIIMManager.QueryInterface(Components.interfaces.nsIAimAdminManager);
  745.     
  746.     if ( pAimAdmin == undefined || pAimAdmin == null )
  747.         return;
  748.  
  749.     adminSetterCallback = new Object();
  750.     adminSetterCallback.ExecuteIfReady = function()
  751.     {
  752.         dump("adminsettercallback executeifready\n");
  753.  
  754.                 // this kinda code is dangerous -- should not glom so many
  755.                 // things that can fail into one statement XXX
  756.  
  757.     Components.classes['@netscape.com/aim/IMManager;1'].getService(Components.interfaces.nsIIMManager).QueryInterface(Components.interfaces.nsIAimAdminManager).ChangeRegistrationStatusPreference(null,parent.lastPrivacyView);
  758.     }
  759.  
  760.     dump("adminsettercallback.execifready\n");
  761.     pAimAdmin.ExecuteIfReady(adminSetterCallback);
  762.  
  763.     var pAimPrefs =  pIIMManager.QueryInterface(Components.interfaces.nsIPrefsManager);
  764.  
  765. dump( "parent.lastChatInvites is " + parent.lastChatInvites + " \n" );
  766.         if ( parent.lastChatInvites != undefined ) {
  767.             pAimPrefs.SetBoolPref("aim.chat.unavailable", parent.lastChatInvites, null, false);
  768.         }
  769.  
  770.     var chatInvite_pref=false;
  771.     try {
  772.         chatInvite_pref= pAimPrefs.GetBoolPref("aim.chat.unavailable", null, false);
  773.         }
  774.     catch (ex) {
  775.         dump("chat announce pref could not be read\n");
  776.         chatInvite_pref = false;
  777.         }
  778.     pChatManager= pIIMManager.QueryInterface(Components.interfaces.nsIAimChatManager);
  779.     // Suresh: Setting it to complement coz the pref is aim.chat._un_available. Gee...This is confusing..heh.
  780.     pChatManager.SetAvailableForChat(!chatInvite_pref);
  781.     dump("Setting chat invite to "+chatInvite_pref+"\n");
  782.  
  783.   try {
  784.     var feedbag = aimFeedbagManager();
  785.     prefmask = feedbag.GetBuddyPrefs();
  786.     // if the idle pref is true and the user just cleared it
  787.     var idlemask = Components.interfaces.nsAimBuddyPrefs.DiscloseIdleTime;
  788.     if(!parent.lastIdle && (prefmask & idlemask))
  789.     {
  790.       prefmask -= idlemask;
  791.       var myaimSession = aimSession();
  792.       aimSession().AimIdleStop(); 
  793.     }
  794.     // if the idle pref is false and it was false to begin with
  795.     else if(!parent.lastIdle && !(prefmask & idlemask))
  796.     {
  797.       return;
  798.     }
  799.     //if the idle pref was true and it is still true
  800.     else if (prefmask & idlemask)
  801.     {
  802.       return;
  803.     }
  804.     //if the idle pref was false and the just turned it on.
  805.     else
  806.     {
  807.       prefmask += idlemask;
  808.     }
  809.     feedbag.SetBuddyPrefs(prefmask);
  810.   }
  811.  
  812.   catch (ex) {}
  813.   return;
  814.  
  815. }
  816.  
  817.  
  818. function
  819. FindAwayMessageTargetByName( msgName )
  820. {
  821.     GetRDFService();
  822.  
  823.     var messages_file = GetRdfFileUrl("default-messages.rdf", "dm.rdf");  
  824.     var datasource = RDF.GetDataSource(messages_file);
  825.  
  826.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  827.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  828.       container.Init(datasource, RDF.GetResource("NC:AIM/AwayMessageBag"));
  829.  
  830.     var elements = container.GetElements();
  831.     var target, node;
  832.     var nameResource = 
  833.                 RDF.GetResource("http://home.netscape.com/NC-rdf#MsgName");
  834.     while ( elements.hasMoreElements() ) {
  835.         node = elements.getNext();
  836.         if ( node ) 
  837.             target = datasource.GetTarget( node, nameResource, 
  838.                 true );
  839.         if ( target ) 
  840.             target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
  841.         if ( target && target.Value == msgName ) 
  842.             return target.Value;
  843.     }
  844.     return null;
  845. }
  846.  
  847. function
  848. EditAwayMessageOnOK()
  849. {
  850.     var nameItem = document.getElementById("awayMessageName");
  851.     var textItem = document.getElementById("awayMessageText");
  852.     var nameValue = null;
  853.     var textValue = null;
  854.  
  855.     if ( !nameItem || nameItem == undefined ) 
  856.         return;
  857.     if ( !textItem || textItem == undefined ) 
  858.         return;
  859.     nameValue = nameItem.value;
  860.     textValue = textItem.value;
  861.     if ( nameValue == "" ) {
  862.         alert(getString("away.EnterLabel"));
  863.         return;
  864.     }
  865.     if ( textValue == "" ) {
  866.         alert(getString("away.EnterMessage"));
  867.         return;
  868.     }
  869.  
  870.     var target = FindAwayMessageTargetByName( nameValue );
  871.     if ( target == null ) {
  872.         retval = confirm(getString("away.DoesNotExist"));
  873.         if ( retval == true ) 
  874.             AssertAwayMessage( nameValue, textValue ); 
  875.         else
  876.             return;
  877.     } else 
  878.         SetAwayMessageTarget( nameValue, textValue )
  879.     top.window.close();
  880. }
  881.  
  882. function
  883. AddAwayMessageOnOK()
  884. {
  885.     var nameItem = document.getElementById("awayMessageName");
  886.     var textItem = document.getElementById("awayMessageText");
  887.     var nameValue = null;
  888.     var textValue = null;
  889.  
  890.     if ( !nameItem || nameItem == undefined ) 
  891.         return;
  892.     if ( !textItem || textItem == undefined ) 
  893.         return;
  894.     nameValue = nameItem.value;
  895.     textValue = textItem.value;
  896.     if ( nameValue == "" ) {
  897.         alert(getString("away.EnterLabel"));
  898.         return;
  899.     }
  900.     if ( textValue == "" ) {
  901.         alert(getString("away.EnterMessage"));
  902.         return;
  903.     }
  904.  
  905.     if ( FindAwayMessageTargetByName( nameValue ) != null ) {
  906.  
  907.         // ask them if they would like to overwrite (i.e., 
  908.         // turn this into an edit).
  909.  
  910.         var response = confirm(getString("away.AlreadyExists"));
  911.         if ( response == true ) {
  912.             EditAwayMessageOnOK();
  913.             return;
  914.         } else {
  915.             alert(getString("away.EnterLabel"));
  916.             return;
  917.         }
  918.     }
  919.  
  920.     AssertAwayMessage( nameValue, textValue ); 
  921.     top.window.close();
  922. }
  923.  
  924. function
  925. AssertAwayMessage( nameValue, textValue )
  926. {
  927.     GetRDFService();
  928.  
  929.     var newmsg = RDF.GetAnonymousResource();
  930.     var messages_file = GetRdfFileUrl("default-messages.rdf", "dm.rdf");  
  931.  
  932.     var datasource = 
  933.         RDF.GetDataSource(messages_file);
  934.     datasource.Assert(newmsg, 
  935.         RDF.GetResource("http://home.netscape.com/NC-rdf#MsgName"),
  936.             RDF.GetLiteral(nameValue), true);
  937.     datasource.Assert(newmsg, 
  938.         RDF.GetResource("http://home.netscape.com/NC-rdf#MsgText"),
  939.         RDF.GetLiteral(textValue), true);
  940.  
  941.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  942.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  943.       container.Init(datasource, RDF.GetResource("NC:AIM/AwayMessageBag"));
  944.  
  945.     container.AppendElement(newmsg);
  946.     datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  947. }
  948.  
  949. function
  950. AddAwayMessage()
  951. {
  952. // title is window.arguments[1];
  953. // content is window.arguments[2];
  954.  
  955.      window.openDialog("chrome://aim/content/AddAwayMessage.xul","_blank", "chrome,close,titlebar,modal", "", "", "");
  956. }
  957.  
  958. function
  959. EditAwayMessage()
  960. {
  961. // title is window.arguments[1];
  962. // content is window.arguments[2];
  963.  
  964.     var msgName, msgText;
  965.     var response;
  966.  
  967.     response = FindSelectedAwayMessage();
  968.     if ( response == null ) {
  969.         alert(getString("away.PleaseSelectToEdit"));
  970.         return;
  971.     } else {
  972.         msgName = response.msgName;
  973.         msgText = response.msgText;
  974.     }
  975.  
  976.      window.openDialog("chrome://aim/content/AddAwayMessage.xul","_blank", "chrome,close,titlebar, modal", "", msgName, msgText);
  977. }
  978.  
  979. function
  980. RemoveAwayMessage()
  981. {
  982.     var msgName, msgText;
  983.     var response;
  984.  
  985.     response = FindSelectedAwayMessage();
  986.     if ( response == null ) {
  987.         alert(getString("away.PleaseSelectToRemove"));
  988.         return;
  989.     } 
  990.  
  991.     answer = confirm(getString("away.AreYouSure").replace(/%AwayMsg%/,response.msgName));
  992.     if ( answer == true ) 
  993.         RemoveTarget( response.msgName );
  994. }
  995.  
  996. function
  997. FindSelectedAwayMessage()
  998. {
  999.         var selection;
  1000.     var tree = document.getElementById("AwayMessages");
  1001.  
  1002.     var response = new Object();
  1003.  
  1004.         if ( tree )
  1005.                 selection = tree.contentView.getItemAtIndex(tree.currentIndex);
  1006.  
  1007.         if ( selection) {
  1008.             response.msgName = selection.getAttribute("MsgName");
  1009.         response.msgText = selection.getAttribute("MsgText");
  1010.  
  1011.         return response;
  1012.     }
  1013.     return null;
  1014. }
  1015.  
  1016.  
  1017.  //XXXVISHY - per screen name stuff
  1018.   
  1019. function getCurrentScreenName()
  1020. {
  1021.   var myaimSession = aimSession();
  1022.   if (myaimSession) {
  1023.     return myaimSession.CurrentScreenName;
  1024.   }
  1025.   else
  1026.     return "";
  1027. }
  1028.  
  1029. // XXXVISHY - the aimPreferenceOnload function MUST be called in the
  1030. // onload handler of every aim preference panel so as to do the
  1031. // per screen name munging
  1032.  
  1033. /* every element has: prefstring, preftype, preattribute, pref (true/false), prefscope(0,1,2)
  1034.  
  1035. preftype, a type of value to retrieve;
  1036. preattribute, a type of element attribute to assign
  1037.  
  1038.  
  1039. preftype = true, if it is for preference element only
  1040. prefscope = 0, PER_SN,
  1041. prefscope = 2, SESSION_GLOBAL,
  1042. prefscope = 1, GEN_GLOBAL
  1043.  
  1044. */
  1045.  
  1046. function aimPreferenceOnload()
  1047. {
  1048.   dump("starting aimPreferenceOnload\n");   
  1049.     var aimprefs = document.getElementsByAttribute("pref", "true");
  1050.     var sN;
  1051.     var qPreference;
  1052.     var curDefPref;
  1053.     var panelType = 0;
  1054.      
  1055.     for (var i = 0 ; i < aimprefs.length ; i++) {
  1056.          var preference = aimprefs[i].getAttribute("prefstring");
  1057.         var curprefScope = aimprefs[i].getAttribute("prefscope");
  1058. dump("curprefScope=" + curprefScope + "\n");        
  1059.         if (curprefScope == 2 || curprefScope == 1) {
  1060.         
  1061.             if (panelType == 0)
  1062.                 qPreference = preference + ".aim";
  1063.             else //panelType == 2
  1064.                 qPreference = preference + ".icq";
  1065.                         
  1066.         }
  1067.         else { // scope == 0, PER_SN
  1068.  
  1069.           if (panelType == aimPrefsManager().GetSessionType()) 
  1070.           {
  1071.             sN = getCurrentScreenName() + "."; 
  1072.             qPreference = sN + preference;
  1073.  
  1074.             if (MozPreferences.getPrefType(qPreference) == Components.interfaces.nsIPrefBranch.PREF_INVALID)
  1075.                  {
  1076.             // first time with this pref, so create a per screen name copy
  1077.                 if (MozPreferences.getPrefType(preference) == Components.interfaces.nsIPrefBranch.PREF_INVALID)
  1078.                  {
  1079.                 // "preference" is not default name, create default name
  1080.                     
  1081.                     if (panelType == 0)
  1082.                         curDefPref = preference + ".aim";
  1083.                     else //panelType == 2
  1084.                         curDefPref = preference + ".icq";
  1085.                 }
  1086.                 else {
  1087.                     curDefPref = preference;
  1088.                 }
  1089. dump("curDefPref=" + curDefPref + "\n");
  1090.  
  1091.                 switch (MozPreferences.getPrefType(curDefPref)) {
  1092.                 case Components.interfaces.nsIPrefBranch.PREF_STRING:
  1093.                 var sPref = MozPreferences.getCharPref(curDefPref);        
  1094.                 MozPreferences.setCharPref(qPreference, sPref);
  1095.                 break;
  1096.                 case Components.interfaces.nsIPrefBranch.PREF_INT:
  1097.                 var iPref = MozPreferences.getIntPref(curDefPref);
  1098.                 MozPreferences.setIntPref(qPreference, iPref);
  1099.                 break;
  1100.                 case Components.interfaces.nsIPrefBranch.PREF_BOOL:
  1101.                 var bPref = MozPreferences.getBoolPref(curDefPref);
  1102.                 MozPreferences.setBoolPref(qPreference, bPref);
  1103.                 break;
  1104.                 default:
  1105.                 dump("Bad pref type for NIM\n");
  1106.                 break;
  1107.                 }
  1108.  
  1109.  
  1110.             }
  1111.           }
  1112.           else
  1113.           {
  1114.             qPreference = "__sys." + preference;
  1115.           
  1116.           }
  1117.  
  1118.             
  1119.         }
  1120.     
  1121.         aimprefs[i].setAttribute("prefstring", qPreference);
  1122.     
  1123.      }
  1124.  
  1125. }
  1126.  
  1127.  
  1128.  
  1129. /*
  1130.     XXXVISHY - this is a hack. The aimPreferenceOnload would have munged
  1131.     aim.mail.presence into a per-screen name pref. This function
  1132.     will unmunge it back into a global preference. This is done in this 
  1133.     ugly manner since it is the least invasive way at this point. 
  1134.  */
  1135.  
  1136. function aimMailPresenceUnMunge()
  1137. {
  1138.     var mailPref = document.getElementById("mailPresence");
  1139.     mailPref.setAttribute("prefstring", "aim.mail.presence");
  1140. }
  1141.  
  1142.  
  1143.  
  1144. /************* Related to the Connection/Proxy Panel ********************/
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150. /*Below all new function for connection panel*/
  1151. /*Below all new function for connection panel*/
  1152. /*Below all new function for connection panel*/
  1153. /*Below all new function for connection panel*/
  1154.  
  1155. //OnLoad AddConnection
  1156. function EditConnectionOnLoad()
  1157. {
  1158.     // window.arguments[1] is type of ops for title,
  1159.     // window.arguments[2] is connection name
  1160.  
  1161.  
  1162.     var panelTtl = document.getElementById("panelTitle");
  1163.  
  1164.     var connectName = document.getElementById("connectName");
  1165.  
  1166. dump("arg1=" + window.arguments[1] + "\narg2=" + window.arguments[2] + "\n");
  1167.     if (window.arguments[1] == "Add") {          
  1168.         panelTtl.setAttribute('title' , panelTtl.getAttribute('titl1'));
  1169.  
  1170.  
  1171.         doSetOKCancel(AddConnMessageOnOK, 0);
  1172.  
  1173.         connLinks.ConnectionName = "";
  1174.         connLinks.SessionType    = 0;
  1175.         connLinks.Host           = "";
  1176.         connLinks.Port           = "";
  1177.         connLinks.ProxyHost      = "";
  1178.         connLinks.ProxyPort      = 1080;
  1179.         connLinks.ProxyUser      = "";
  1180.         connLinks.ProxyPassword  = "";
  1181.         connLinks.ProxyProtocol  = 0;
  1182.         connLinks.IsProxy        = false;
  1183.         connLinks.ConnectionType = 0;
  1184.         
  1185.     }
  1186.     else { /* Edit mode */
  1187.         panelTtl.setAttribute('title' , panelTtl.getAttribute('titl2'));
  1188.         
  1189.  
  1190.         doSetOKCancel(EditConnMessageOnOK, 0);
  1191.         
  1192.         var curConnName = window.arguments[2];
  1193.  
  1194.         setValuesFromRDF (curConnName);
  1195.  
  1196.     }
  1197.         
  1198.     setConnUI();
  1199.     
  1200.     DoFullEnabling();
  1201.     
  1202. }
  1203.  
  1204. function setValuesFromRDF (connectionName)
  1205. {
  1206. dump("starting setValuesFromRDF\n");    
  1207.     GetRDFService();
  1208.  
  1209.     var messages_file = CopynGetUrl("default-connections.rdf", "connections.rdf");  
  1210.     var datasource = RDF.GetDataSource(messages_file);
  1211.         
  1212.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  1213.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  1214.       container.Init(datasource, RDF.GetResource("NC:AIM/ConnectionsSeq"));
  1215.  
  1216.     var ConnNameLiteral = RDF.GetLiteral(connectionName);
  1217.  
  1218.     var ConnName = RDF.GetResource("http://home.netscape.com/NC-rdf#ConnectionName");
  1219.  
  1220.     var node = datasource.GetSource (ConnName, ConnNameLiteral, true);
  1221.  
  1222.     if (node)
  1223.     {
  1224.         var curName;
  1225.         for (var linkName in connLinks)
  1226.         {
  1227.             curName = datasource.GetTarget (node, 
  1228.                                             RDF.GetResource("http://home.netscape.com/NC-rdf#" + linkName),
  1229.                                             true);
  1230.             if ( curName ) {
  1231.                 curName = curName.QueryInterface(Components.interfaces.nsIRDFLiteral);
  1232.                 connLinks[linkName] = curName.Value;
  1233.             }
  1234.         }
  1235.     }
  1236.  
  1237. }
  1238.  
  1239. function DoFullEnabling() {
  1240.  
  1241.     var connectName = document.getElementById("connectName");
  1242.     var aimHost = document.getElementById("aimHost");
  1243.     var aimPort = document.getElementById("aimPort");
  1244.  
  1245.     var Name = connectName.value;
  1246.  
  1247.     if (Name == "AIM" || Name == "AOL" || Name == "ICQ") {
  1248.         connectName.setAttribute( "disabled", "true" );
  1249.         aimHost.setAttribute( "disabled", "true" );
  1250.     }
  1251.     else {
  1252.         if (window.arguments[1] == "Add") {
  1253.             connectName.setAttribute( "disabled", "false" );
  1254.             connectName.removeAttribute( "disabled" );
  1255.         }
  1256.         else { // Edit
  1257.             connectName.setAttribute( "disabled", "true" );        
  1258.         }
  1259.  
  1260.         aimHost.setAttribute( "disabled", "false" );
  1261.         aimHost.removeAttribute( "disabled" );
  1262.  
  1263.     }
  1264.  
  1265.     // enable proxy protocol fields
  1266.     DoEnabling();
  1267. }
  1268.  
  1269. //OnLoad pref-IM_connection.xul
  1270. function PrefIMConnectionOnLoad(){
  1271.     // init datasource
  1272. dump("starting PrefIMConnectionOnLoad\n");
  1273.  
  1274.     GetRDFService();
  1275.  
  1276.     // copy file to profile  and return full URL of the file
  1277.     var connection_file = CopynGetUrl("default-connections.rdf", "connections.rdf");
  1278.  
  1279.     if (!connection_file)
  1280.         return;
  1281.  
  1282.     datasource = RDF.GetDataSource(connection_file);
  1283.  
  1284.     dump( "datasource " + datasource + "\n" );
  1285.  
  1286.     var tree = document.getElementById("ConnectionList");
  1287.     tree.database.AddDataSource(datasource);
  1288.     tree.setAttribute('ref', tree.getAttribute('ref'));
  1289.  
  1290.     // disable 2 buttons, no selection here
  1291.     document.getElementById("btnEdit").setAttribute("disabled", true);
  1292.     document.getElementById("btnRemove").setAttribute("disabled", true);
  1293. }
  1294.  
  1295.  
  1296. function FindSelectedConnection(connInfo)
  1297. {
  1298.     var selection;
  1299.     var list = document.getElementById("ConnectionList");
  1300. dump("starting FindSelectedConnection\n");
  1301.  
  1302.  
  1303.     if ( list && list.selectedItem ) {
  1304.              connInfo.name          = list.selectedItem.getAttribute("ConnectionName");
  1305.              connInfo.sessiontype   = list.selectedItem.getAttribute("sessionType");
  1306. dump("connInfo.name=" + connInfo.name + " connInfo.sessiontype=" + connInfo.sessiontype + "\n");
  1307.             return connInfo;
  1308.         
  1309.     }
  1310.     return null;
  1311. }
  1312.  
  1313.  
  1314. // 3 buttons
  1315. function AddConnMessage()
  1316. {
  1317. dump("starting AddConnMessage\n");
  1318.  
  1319.     window.openDialog("chrome://aim/content/pref-IM_addconnection.xul","_blank", "chrome,close,titlebar,modal", "", "Add", "");
  1320.     
  1321. }
  1322.  
  1323. function EditConnMessage()
  1324. {
  1325. dump("starting EditConnMessage\n");
  1326.  
  1327.     var ConnectionInfo = new Object();
  1328.     ConnectionInfo.name ="";
  1329.     ConnectionInfo.sessiontype = "";
  1330.  
  1331.  
  1332.     FindSelectedConnection(ConnectionInfo);
  1333.     var ConnectionName = ConnectionInfo.name;
  1334.  
  1335. dump("ConnectionName=" + ConnectionName + "\n");
  1336.     if ( ConnectionName == null ) {
  1337.         alert(getString("connection.PleaseSelectToEdit"));
  1338.         return;
  1339.     }     
  1340.  
  1341.     window.openDialog("chrome://aim/content/pref-IM_addconnection.xul","_blank", "chrome,close,titlebar, modal", "", "Edit", ConnectionName);
  1342.  
  1343. }
  1344.  
  1345. function RemoveConnMessage()
  1346. {
  1347. dump("starting RemoveConnMessage\n");
  1348.  
  1349.     var ConnectionInfo = new Object();
  1350.     ConnectionInfo.name ="";
  1351.     ConnectionInfo.sessiontype = "";
  1352.  
  1353.  
  1354.     FindSelectedConnection(ConnectionInfo);
  1355.     var ConnectionName = ConnectionInfo.name;
  1356.  
  1357.     if ( ConnectionName == null ) {
  1358.         alert(getString("connection.PleaseSelectToRemove"));
  1359.         return;
  1360.     }
  1361.  
  1362.     var answer = confirm(getString("connection.AreYouSure").replace(/%AwayMsg%/, ConnectionName));
  1363.  
  1364.     if ( answer == true ) 
  1365.         RemoveConnectionfromDatasrc( ConnectionName );
  1366.  
  1367.  
  1368. }
  1369.  
  1370.  
  1371. function RemoveConnectionfromDatasrc( ConnectionName )
  1372. {
  1373.     GetRDFService();
  1374.  
  1375.     var messages_file = CopynGetUrl("default-connections.rdf", "connections.rdf");  
  1376.     var datasource = RDF.GetDataSource(messages_file);
  1377.         
  1378.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  1379.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  1380.       container.Init(datasource, RDF.GetResource("NC:AIM/ConnectionsSeq"));
  1381.  
  1382.     var ConnNameLiteral = RDF.GetLiteral(ConnectionName);
  1383.  
  1384.     var ConnName = RDF.GetResource("http://home.netscape.com/NC-rdf#ConnectionName");
  1385.  
  1386.     var node = datasource.GetSource (ConnName, ConnNameLiteral, true);
  1387.  
  1388.     if (node) {
  1389.         // remove from container
  1390.         container.RemoveElement( node, true );
  1391.  
  1392.         // remove connection info
  1393.         var curProp;
  1394.         var curTarget;
  1395.         for (var curName in connLinks)
  1396.         {
  1397.           curProp   = RDF.GetResource("http://home.netscape.com/NC-rdf#" + curName);
  1398.           curTarget = datasource.GetTarget(node, curProp, true);
  1399.             
  1400.           datasource.Unassert (node, curProp, curTarget );
  1401.         }        
  1402.  
  1403.         datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  1404.     }
  1405.  
  1406.     return null;
  1407.  
  1408. }
  1409.  
  1410.  
  1411. //2 callbacks for AddConnection editing window
  1412. function AddConnMessageOnOK()
  1413. {
  1414.     dump("starting AddConnMessageOnOK\n");
  1415.     GetRDFService();
  1416.  
  1417.     var messages_file = CopynGetUrl("default-connections.rdf", "connections.rdf");  
  1418.     var datasource = RDF.GetDataSource(messages_file);
  1419.  
  1420.     var connectName = document.getElementById("connectName");
  1421.     var connectNameVal = connectName.value;
  1422.  
  1423. dump("connectNameVal=" + connectNameVal + "\n");
  1424.     if (connectNameVal == "")
  1425.     {
  1426.         alert(getString("connection.EnterName"));
  1427.         return;
  1428.     }
  1429.  
  1430.     var node = datasource.GetSource (RDF.GetResource("http://home.netscape.com/NC-rdf#ConnectionName"), 
  1431.                                      RDF.GetLiteral(connectNameVal), 
  1432.                                      true);
  1433.  
  1434.     if (node) {
  1435.         alert(getString("connection.AlreadyExists"));
  1436.         return;
  1437.     }
  1438.     
  1439.  
  1440.     getConnInfoFromUI();
  1441.  
  1442.     AddConnectionDatasource ();
  1443.     top.window.close();
  1444. }
  1445.  
  1446. function EditConnMessageOnOK()
  1447. {
  1448.     GetRDFService();
  1449.  
  1450.     var messages_file = CopynGetUrl("default-connections.rdf", "connections.rdf");  
  1451.     var datasource = RDF.GetDataSource(messages_file);
  1452.  
  1453.     var connectNameVal = document.getElementById("connectName").value;
  1454.  
  1455.     var node = datasource.GetSource (RDF.GetResource("http://home.netscape.com/NC-rdf#ConnectionName"), 
  1456.                                      RDF.GetLiteral(connectNameVal), 
  1457.                                      true);
  1458.  
  1459.     if (!node)
  1460.         return;
  1461.  
  1462.     getConnInfoFromUI();
  1463.  
  1464.     EditConnectionDatasource(node);
  1465.     top.window.close();
  1466. }
  1467.  
  1468. function setConnUI()
  1469. {
  1470.  
  1471.     var panelSessionType = 0;
  1472.  
  1473.     var connectName = document.getElementById("connectName");
  1474.     var aimHost = document.getElementById("aimHost");
  1475.     var aimPort = document.getElementById("aimPort");
  1476.     var proxyHost = document.getElementById("proxyHost");
  1477.     var proxyPort = document.getElementById("proxyPort");
  1478.     var proxyUserName = document.getElementById("proxyUserName");
  1479.     var proxyPassword = document.getElementById("proxyPassword");
  1480.     var proxyUse = document.getElementById("proxyUse");
  1481.     var proxyProtocol = document.getElementById("proxyProtocol");
  1482.  
  1483.     if (panelSessionType != 2)
  1484.        var IsAol = document.getElementById("IsAol");
  1485.  
  1486.     connectName.value = connLinks.ConnectionName;
  1487.  
  1488.     aimHost.value = connLinks.Host;    
  1489.     aimPort.value = connLinks.Port;    
  1490.     proxyHost.value = connLinks.ProxyHost;    
  1491.     proxyPort.value = connLinks.ProxyPort;    
  1492.     proxyUserName.value = connLinks.ProxyUser;    
  1493.  
  1494.     var pIAimSession = aimSession();
  1495.        if ( pIAimSession ) {
  1496.            proxyPassword.value = pIAimSession.UnMungeString(connLinks.ProxyPassword);
  1497. dump("UnMungeString connLinks.ProxyPassword=" + connLinks.ProxyPassword + " proxyPassword.value=" + proxyPassword.value + "\n");
  1498.        }
  1499.  
  1500.     
  1501.     if (connLinks.ProxyProtocol > 0 && connLinks.ProxyProtocol <= 4)
  1502.         proxyProtocol.selectedItem = proxyProtocol.childNodes[connLinks.ProxyProtocol - 1];
  1503.     else
  1504.         proxyProtocol.selectedItem = proxyProtocol.childNodes[0];
  1505.  
  1506.  
  1507.     if (connLinks.IsProxy == "true")
  1508.       proxyUse.setAttribute ("checked", true);
  1509.     else
  1510.       proxyUse.setAttribute ("checked", false);
  1511.  
  1512. /*    proxyUse.checked= connLinks.IsProxy;*/
  1513.  
  1514. dump("proxyUse.checked=" + proxyUse.checked + "  connLinks.IsProxy=" + connLinks.IsProxy + "\n");
  1515.  
  1516.     if (panelSessionType != 2) {
  1517.         if (connLinks.ConnectionType == 1)
  1518.             proxyUse.setAttribute ("checked", true);
  1519.         else
  1520.             proxyUse.setAttribute ("checked", false);
  1521.         
  1522.     }
  1523.  
  1524. }
  1525.  
  1526. // Remove whitespace from both ends of a string
  1527. function TrimString(string)
  1528. {
  1529.   if (!string) return "";
  1530.   return string.replace(/(^\s+)|(\s+$)/g, '')
  1531. }
  1532.  
  1533. function getConnInfoFromUI()
  1534. {
  1535. dump("starting getConnInfoFromUI\n");
  1536.     var panelSessionType = 0;
  1537.  
  1538.     var connectName = document.getElementById("connectName");
  1539.     var aimHost = document.getElementById("aimHost");
  1540.     var aimPort = document.getElementById("aimPort");
  1541.     var proxyHost = document.getElementById("proxyHost");
  1542.     var proxyPort = document.getElementById("proxyPort");
  1543.     var proxyUserName = document.getElementById("proxyUserName");
  1544.     var proxyPassword = document.getElementById("proxyPassword");
  1545.     var proxyUse = document.getElementById("proxyUse");
  1546.     var proxyProtocol = document.getElementById("proxyProtocol");
  1547.     var IsAol = document.getElementById("IsAol");
  1548.  
  1549.     connLinks.ConnectionName =  TrimString(connectName.value);
  1550.     connLinks.SessionType    =  panelSessionType;
  1551. dump("connLinks.SessionType=" + connLinks.SessionType + "\n");
  1552.     connLinks.Host           =  TrimString(aimHost.value);    
  1553.     connLinks.Port           =  TrimString(aimPort.value);    
  1554.     connLinks.ProxyHost      =  TrimString(proxyHost.value);    
  1555.     connLinks.ProxyPort      =  TrimString(proxyPort.value);    
  1556.     connLinks.ProxyUser      =  TrimString(proxyUserName.value);
  1557.  
  1558.     var pIAimSession = aimSession();
  1559.     if(pIAimSession) {
  1560.         // trim?
  1561.            connLinks.ProxyPassword = pIAimSession.MungeString(proxyPassword.value);
  1562. dump("MungeString proxyPassword.value=" + proxyPassword.value + " connLinks.ProxyPassword=" + connLinks.ProxyPassword + "\n");
  1563.  
  1564.     }
  1565.     
  1566.     // trim?
  1567.                 
  1568.     connLinks.ProxyProtocol  =  proxyProtocol.selectedItem.getAttribute("value");
  1569.     connLinks.IsProxy        =  proxyUse.checked;
  1570.  
  1571.  
  1572. dump("isaolchecked=" + IsAol.checked + "\n");
  1573.     if (panelSessionType != 2) {
  1574.         if (IsAol.checked)
  1575.             connLinks.ConnectionType = 1;
  1576.         else
  1577.             connLinks.ConnectionType = 0;
  1578.         
  1579.     }
  1580.     else
  1581.         connLinks.ConnectionType = 2;
  1582. }
  1583.  
  1584. function AddConnectionDatasource()
  1585. {
  1586.     GetRDFService();
  1587.  
  1588.     var messages_file = CopynGetUrl("default-connections.rdf", "connections.rdf");  
  1589.     var datasource = RDF.GetDataSource(messages_file);
  1590.  
  1591.     var newConn = RDF.GetAnonymousResource();
  1592.  
  1593.     for (var curName in connLinks)     
  1594.     {
  1595.         datasource.Assert(newConn, RDF.GetResource("http://home.netscape.com/NC-rdf#" + curName),        
  1596.                 RDF.GetLiteral(connLinks[curName]), true);
  1597.     }
  1598.  
  1599.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  1600.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  1601.       container.Init(datasource, RDF.GetResource("NC:AIM/ConnectionsSeq"));
  1602.  
  1603.     container.AppendElement(newConn);
  1604.     datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  1605.  
  1606. }
  1607.  
  1608.  
  1609. function EditConnectionDatasource( connectionNode )
  1610. {
  1611.     GetRDFService();
  1612.  
  1613.     var messages_file = CopynGetUrl("default-connections.rdf", "connections.rdf");  
  1614.     var datasource = RDF.GetDataSource(messages_file);
  1615.  
  1616.     var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  1617.       container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  1618.       container.Init(datasource, RDF.GetResource("NC:AIM/ConnectionsSeq"));
  1619.  
  1620.     var curLinkRes;
  1621.     var oldTarget;
  1622.     for(var curName in connLinks) 
  1623.     {
  1624.         if (curName != "ConnectionName") {// ConnectionName was set already
  1625.             curLinkRes = RDF.GetResource("http://home.netscape.com/NC-rdf#" + curName);
  1626.             oldTarget  = datasource.GetTarget(connectionNode, curLinkRes, true);
  1627.                                                                                           
  1628.             datasource.Change( connectionNode, curLinkRes,                               
  1629.                                oldTarget, RDF.GetLiteral(connLinks[curName]) );                               
  1630.         }
  1631.     }
  1632.  
  1633.         
  1634.     datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
  1635.  
  1636. }
  1637. /* keep for the future UI
  1638. function SetExternalConnection()
  1639. {
  1640.     var ConnectionInfo = new Object();
  1641.     ConnectionInfo.name ="";
  1642.     ConnectionInfo.sessiontype = "";
  1643.  
  1644.  
  1645.     FindSelectedConnection(ConnectionInfo);
  1646.     var ConnectionName = ConnectionInfo.name;
  1647.  
  1648.     document.getElementById("mailConn").value = ConnectionName;
  1649.     setConnectionInfo (ConnectionName, "mail");
  1650.  
  1651. }
  1652. */
  1653.  
  1654. function SetHostPortDefault(type)
  1655. {
  1656.  
  1657. dump("type=" + type + "\n");
  1658.     var host = document.getElementById("aimHost"); 
  1659.     var port = document.getElementById("aimPort");
  1660.  
  1661.     var aol = document.getElementById("IsAol").checked;
  1662.  
  1663.     if (aol) {
  1664.         host.setAttribute("value", "americaonline.aol.com");
  1665.         port.setAttribute("value", "5200"); 
  1666.     }
  1667.     else {
  1668.         host.setAttribute("value", "login.oscar.aol.com");
  1669.         port.setAttribute("value", "5190");         
  1670.     }
  1671.     
  1672.  
  1673.  
  1674. }
  1675.  
  1676. function EnableConnButtons()
  1677. {
  1678.     var connInfo = new Object();
  1679.     connInfo.name ="";
  1680.     connInfo.sessiontype = "";
  1681.  
  1682.  
  1683.     FindSelectedConnection(connInfo);
  1684.     var ConnectionName = connInfo.name;
  1685.  
  1686.     var panelSessionType = 0;
  1687. dump("connInfo.name =" + connInfo.name + " connInfo.sessiontype=" + connInfo.sessiontype + 
  1688.      "panelSessionType=" + panelSessionType + "\n");
  1689.  
  1690.     if(connInfo.sessiontype == panelSessionType) {
  1691.         document.getElementById("btnEdit").setAttribute("disabled", false);
  1692.         document.getElementById("btnEdit").removeAttribute( "disabled" );    
  1693.        
  1694.     }
  1695.     else {
  1696.         document.getElementById("btnEdit").setAttribute("disabled", true);    
  1697.     }
  1698.  
  1699.  
  1700.     if (connInfo.name == "AIM" || connInfo.name == "AOL" || connInfo.name == "ICQ" ||
  1701.         (connInfo.sessiontype != panelSessionType)) {
  1702.     
  1703.         document.getElementById("btnRemove").setAttribute("disabled", true);
  1704.     
  1705.     }
  1706.     else {
  1707.         document.getElementById("btnRemove").setAttribute("disabled", false);
  1708.         document.getElementById("btnRemove").removeAttribute( "disabled" ); 
  1709.     }
  1710.  
  1711.  
  1712. }
  1713.  
  1714.  
  1715. // new update
  1716.  
  1717. function PrefIMConnectionOnload()
  1718. {
  1719.    var proxPass = "";
  1720.    DoEnabling();
  1721.    parent.ConnectionLoad = 1;
  1722.    parent.connectionSaved = 0;
  1723.    if ( parent.ConnectionCallback == undefined || 
  1724.         parent.ConnectionCallback == null ) {
  1725.  
  1726.     // Register the OK callback func once, and unmunge the initial value 
  1727.  
  1728.     parent.ConnectionCallback = 1;
  1729.        parent.hPrefWindow.registerOKCallbackFunc( AssertProxyChanges );
  1730.        var pIAimSession = aimSession();
  1731.        if ( pIAimSession ) {
  1732.            proxPass = pIAimSession.UnMungeString(document.getElementById("proxyPassword").value);
  1733.         parent.proxyPassword = proxPass;
  1734.        }
  1735.    } else {
  1736.  
  1737.     // we switched back from some other panel, so restore the 
  1738.     // saved off value from the unload handler
  1739.  
  1740.     proxPass = parent.proxyPassword;    
  1741.    }
  1742.    document.getElementById("proxyPassword").value = proxPass;
  1743. }
  1744.  
  1745. function
  1746. AssertProxyChanges()
  1747. {
  1748.     // if the connection panel is loaded, base64 the current password
  1749.  
  1750.     if ( parent.ConnectionLoad == 1 )
  1751.         MungeProxyPassword();
  1752.  
  1753.     // set this so the unload handler doesn't do anything when called
  1754.  
  1755.     parent.connectionSaved = 1;
  1756. }
  1757.  
  1758. function PrefIMConnectionOnunload()
  1759. {
  1760.     // we already saved (e.g., here because OK was hit), so juswt return
  1761.  
  1762.     if ( parent.connectionSaved == 1 )
  1763.         return;
  1764.  
  1765.     // ok, switching to some other panel. Save off the current value
  1766.     // to be restored in the onload handler, and remember we are not
  1767.     // visible so we deal with the AssertProxyChanges() callback in
  1768.     // the correct manner
  1769.  
  1770.     parent.proxyPassword = document.getElementById("proxyPassword").value;
  1771.     MungeProxyPassword();        // just in case OK is hit while away
  1772.     parent.ConnectionLoad = 0;    
  1773. }
  1774.  
  1775. function DoEnabling()
  1776. {
  1777.   var host = document.getElementById("proxyHost");
  1778.   var port = document.getElementById("proxyPort");
  1779.   var protocol = document.getElementById("proxyProtocol");
  1780.   var userName = document.getElementById("proxyUserName");
  1781.   var password = document.getElementById("proxyPassword");
  1782.   var radiogroup0 = document.getElementById("proxyProtocolSocks4");
  1783.   var radiogroup1 = document.getElementById("proxyProtocolSocks5");
  1784.   var radiogroup2 = document.getElementById("proxyProtocolHttps");
  1785.   var radiogroup3 = document.getElementById("proxyProtocolHttp");
  1786.  
  1787.   // convenience arrays
  1788.   var manual = [host, port, protocol, userName, password, radiogroup0, radiogroup1, radiogroup2, radiogroup3];
  1789.   
  1790.   // checkbox button
  1791.   var checkboxitem = document.getElementById("proxyUse");
  1792.   if ( checkboxitem.checked ) {
  1793.       for( var i = 0; i < manual.length; i++ ) {
  1794.         manual[i].setAttribute( "disabled", "false" );
  1795.         manual[i].removeAttribute( "disabled" );
  1796.       }
  1797.   } else {
  1798.       for( var i = 0; i < manual.length; i++ ) 
  1799.         manual[i].setAttribute( "disabled", "true" );
  1800.   }
  1801. }
  1802.  
  1803.  
  1804. function MungeProxyPassword()
  1805. {
  1806.     //XXXVISHY - you cannot use macros like AimSessionObject in
  1807.         // any callback because the javascript context will not remember
  1808.         // the included files!!!
  1809.  
  1810.         var IMServiceClass = Components.classes['@netscape.com/aim/IMManager;1'];
  1811.         var pIIMManager  = IMServiceClass.getService(Components.interfaces.nsIIMManager)
  1812.         var pIAimSession = pIIMManager.QueryInterface(Components.interfaces.nsIAimSession)
  1813.         var proxPass = "";
  1814.         if(pIAimSession) {
  1815.                proxPass = pIAimSession.MungeString(document.getElementById("proxyPassword").value);
  1816.               document.getElementById("proxyPassword").value = proxPass;
  1817.         }
  1818. }
  1819.  
  1820.  
  1821. function resetConnection()
  1822. {
  1823. dump("IM reset\n");
  1824.     document.getElementById("aimHost").value = "login.oscar.aol.com"
  1825.     document.getElementById("aimPort").value = "5190";
  1826. }
  1827.  
  1828.  
  1829. /*connection panel end*/
  1830.  
  1831.  
  1832. function UpdateAwayButtons()
  1833. {
  1834.   var selection;
  1835.   var tree = document.getElementById("AwayMessages");
  1836.   if (tree)
  1837.     selection = tree.contentView.getItemAtIndex(tree.currentIndex);
  1838.   if ( selection ) {
  1839.     document.getElementById("buttonEditMess").setAttribute("disabled", "false");
  1840.     var parent = selection.parentNode;
  1841.     if (parent.childNodes.length != 1) {
  1842.       // If this is the last element in away tree, do not allow remove
  1843.       document.getElementById("buttonRemoveMess").setAttribute("disabled", "false");
  1844.     }
  1845.   }        
  1846.   return;
  1847. }
  1848.  
  1849. function DisableButtons()
  1850. {
  1851.     document.getElementById("buttonEditMess").setAttribute("disabled", "true");
  1852.     document.getElementById("buttonRemoveMess").setAttribute("disabled", "true");
  1853. }
  1854.  
  1855. function PrefIMBuddyIconOnLoad() {
  1856.   if( (false == IsSignedOn()) || (isIcq() == true) ) {
  1857.     var offlinetxt = aimString("bi.plsfirstsignon");
  1858.     var element = document.getElementById("OfflineIntro");
  1859.     var textNode = document.createTextNode(offlinetxt);
  1860.     element.appendChild(textNode);
  1861.     DisableBIElements();
  1862.     return;
  1863.   }
  1864.  
  1865.   var nimBuddy = aimBuddyManager();
  1866.   nimBuddy.InitBuddyIconsState();
  1867.  
  1868.   //select the first element *My Buddy Icon* on pref load.
  1869.   var buddyTree = document.getElementById("buddyIconTree");
  1870.   var treeselection = buddyTree.treeBoxObject.selection;
  1871.   treeselection.select(0);
  1872.  
  1873.  
  1874.   document.getElementById("OfflineIntro").setAttribute("hidden", "true");
  1875.   LoadPersonalBuddyIcon();
  1876. }
  1877.  
  1878. function buddyIconBrowse() {
  1879.   var buddyTree = document.getElementById("buddyIconTree");
  1880.   var startIndex = {};
  1881.   var endIndex = {};
  1882.   buddyTree.treeBoxObject.selection.getRangeAt(0, startIndex, endIndex);
  1883.   var sindex = startIndex.value;
  1884.   var eindex = endIndex.value;
  1885.   var view = buddyTree.treeBoxObject.view;
  1886.   var level = view.getLevel(sindex);
  1887.   var selectedItem = view.getCellText(sindex, "ListSetupCol");
  1888.  
  1889.   if ((level == 0) && (sindex > 0)) {
  1890.     //some group is selected....just return;
  1891.     return;
  1892.   }
  1893.  
  1894.   var ioService = GetIOService();
  1895.   var currentTime = new Date().getTime();
  1896.   var biimage = document.getElementById("buddyIconImage");
  1897.   var pIAimSession = pIIMManager.QueryInterface(Components.interfaces.nsIAimSession);
  1898.   var pDir = pIAimSession.profileDir;
  1899.   
  1900.   //set the image to current picture.gif
  1901.   var pictureDir = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  1902.   pictureDir.initWithPath(pDir.path);
  1903.  
  1904.   //buddy picture directory.
  1905.   var bpictureDir = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  1906.   bpictureDir.initWithPath(pDir.path);
  1907.     
  1908.   var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
  1909.   if (!fp) {
  1910.     dump("Unable to create file picker...\n");
  1911.     return;
  1912.   }
  1913.   fp.init(window, aimString("bibrowse.title"),  Components.interfaces.nsIFilePicker.modeOpen);
  1914.   fp.appendFilter(aimString("bi.filetypes"), "*.gif;*.jpg;*.bmp;*.ico;*.xbm");
  1915.   var ret = fp.show();
  1916.   if (ret == Components.interfaces.nsIFilePicker.returnOK && fp.fileURL.spec) {
  1917.     var fileurl = fp.fileURL.spec;
  1918.     var Ifile = fp.fileURL.file;
  1919.     var filesize = Ifile.fileSize;
  1920.     if(filesize > 7168) {
  1921.       aimErrorBox(aimString("bi.toolarge"));
  1922.       return;
  1923.     }
  1924.   }
  1925.  
  1926.   //if the slected item is *my BI* then do this
  1927.   if ((level == 0) && (selectedItem == "*My Buddy Icon*") && (sindex == 0)) {
  1928.     pictureDir.append("picture.gif");
  1929.     if (pictureDir.exists()) {
  1930.       //delete the existing file
  1931.       pictureDir.remove(false);
  1932.     }
  1933.  
  1934.     Ifile.copyTo(pDir, "picture.gif");
  1935.     var anotherPictureDir = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  1936.     anotherPictureDir.initWithPath(pDir.path);
  1937.     anotherPictureDir.append("picture.gif");
  1938.     if (anotherPictureDir.exists()) {
  1939.       var tfileurl = ioService.getURLSpecFromFile(anotherPictureDir);
  1940.       if (biimage) {
  1941.         //The picture.gif will be stored in cache. so everytime you click browse and change you image
  1942.         //the url remains the same and it loads from cache. That's the reason a unique value is used.
  1943.         biimage.setAttribute("src", tfileurl+"?foobar="+currentTime);
  1944.       }
  1945.     }
  1946.  
  1947.     try {
  1948.       pIAimSession.SetBuddyIcon(false);
  1949.     }
  1950.     catch(e) {
  1951.       dump("Error setting Buddy Icon...:" + e + "\n");
  1952.     }
  1953.   } //end of setting personal BI
  1954.   else {
  1955.     pictureDir.append("picture");
  1956.     if(!pictureDir.exists()) {
  1957.       return;
  1958.     }
  1959.     bpictureDir.append("picture");
  1960.     if(!bpictureDir.exists()) {
  1961.       return;
  1962.     }
  1963.  
  1964.     pictureDir.append(selectedItem+".gif");
  1965.     if (pictureDir.exists()) {
  1966.       //delete the existing one
  1967.       pictureDir.remove(false);
  1968.     }
  1969.  
  1970.     var newfileName = selectedItem + ".gif";
  1971.     Ifile.copyTo(bpictureDir, newfileName);
  1972.     bpictureDir.append(newfileName);
  1973.     if (!bpictureDir.exists()) {
  1974.       return;
  1975.     }
  1976.     var buddyBI = ioService.getURLSpecFromFile(bpictureDir);
  1977.     if (biimage) {
  1978.       //The picture.gif will be stored in cache. so everytime you click browse and change you image
  1979.       //the url remains the same and it loads from cache. That's the reason a unique value is used.
  1980.       biimage.setAttribute("src", buddyBI+"?foobar="+currentTime);
  1981.     }
  1982.  
  1983.  
  1984.     //this guy should set the reject flag in *defaulr-BI.rdf* (Not in Buddy List DS)
  1985.     // for this buddy so that the user won't receive BI from that remote Buddy.
  1986.     //this guy should also call the main RDF code to set the hasBI property.
  1987.     var rdf = aimRDF();
  1988.     var nimIM = aimIM();
  1989.     nimIM.SetHasBIBuddyIconFlag(selectedItem, true);
  1990.  
  1991.     var wantBIres = rdf.GetResource("http://home.netscape.com/NC-rdf#WantBI");
  1992.     var falseliteral = rdf.GetLiteral("false");
  1993.     nimIM.SetBuddyIconFlag(selectedItem, wantBIres, falseliteral);
  1994.  
  1995.     var nimBuddy = aimBuddyManager();
  1996.     nimBuddy.SetHasBuddyIconFlag(selectedItem, true);
  1997.  
  1998.   } //else 
  1999. }
  2000.  
  2001. function GetIOService()
  2002. {
  2003.   var IOService = Components.classes["@mozilla.org/network/io-service;1"]
  2004.                     .getService(Components.interfaces.nsIIOService);
  2005.  
  2006.   return IOService;
  2007. }
  2008.  
  2009. function clearBuddyIcon()
  2010. {
  2011.   var userresponse;
  2012.   userresponse = confirm(getString("bi.clearbi"));
  2013.   if (userresponse == false) 
  2014.     return;
  2015.  
  2016.   var buddyTree = document.getElementById("buddyIconTree");
  2017.   var startIndex = {};
  2018.   var endIndex = {};
  2019.   buddyTree.treeBoxObject.selection.getRangeAt(0, startIndex, endIndex);
  2020.   var sindex = startIndex.value;
  2021.   var eindex = endIndex.value;
  2022.   var view = buddyTree.treeBoxObject.view;
  2023.   var level = view.getLevel(sindex);
  2024.   var selectedItem = view.getCellText(sindex, "ListSetupCol");
  2025.   var biimage = document.getElementById("buddyIconImage");
  2026.   var pIAimSession = pIIMManager.QueryInterface(Components.interfaces.nsIAimSession);
  2027.   var pDir = pIAimSession.profileDir;
  2028.   
  2029.   //set the image to current picture.gif
  2030.   var pictureDir = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  2031.   pictureDir.initWithPath(pDir.path);
  2032.  
  2033.   if ((level == 0) && (selectedItem == "*My Buddy Icon*") && (sindex == 0)) {
  2034.     clearPersonalBuddyIcon();
  2035.     clearBuddyIconImage();
  2036.     return;
  2037.   }
  2038.  
  2039.   if ((level == 0) && (sidex > 0)) {
  2040.     //a group is selected
  2041.     return;
  2042.   }
  2043.  
  2044.   //three steps done.
  2045.   //1. Delete the <SN>.gif
  2046.   //2. Clear the RejectBI flag, if any.
  2047.   //3. Clear the HasBI flag, if any.
  2048.  
  2049.   pictureDir.append("picture");
  2050.   if (!pictureDir.exists()) {
  2051.     return;
  2052.   }
  2053.   pictureDir.append(selectedItem+".gif");
  2054.   if (pictureDir.exists()) {
  2055.     //remove the picture file
  2056.     pictureDir.remove(false);
  2057.   }
  2058.  
  2059.   
  2060.   var nimIM = aimIM();
  2061.   nimIM.SetHasBIBuddyIconFlag(selectedItem, false);
  2062.   var rdf = aimRDF();
  2063.  
  2064.   //clear wantBI flag
  2065.   var wantBIres = rdf.GetResource("http://home.netscape.com/NC-rdf#WantBI");
  2066.   var trueliteral = rdf.GetLiteral("true");
  2067.   nimIM.SetBuddyIconFlag(selectedItem, wantBIres, trueliteral);
  2068.  
  2069.   //clear reject BI flag
  2070.   var rejBIres = rdf.GetResource("http://home.netscape.com/NC-rdf#Reject");
  2071.   var falseliteral = rdf.GetLiteral("false");
  2072.   nimIM.SetBuddyIconFlag(selectedItem, rejBIres, falseliteral);
  2073.  
  2074.   //clear FileSize BI res
  2075.   var filesizeBIres = rdf.GetResource("http://home.netscape.com/NC-rdf#FileSize");
  2076.   var filesizeliteral = rdf.GetIntLiteral(0);
  2077.   nimIM.SetBuddyIconFlag(selectedItem, filesizeBIres, filesizeliteral);
  2078.  
  2079.   //clear checksum BI res
  2080.   var checksumBIres = rdf.GetResource("http://home.netscape.com/NC-rdf#CheckSum");
  2081.   var csliteral = rdf.GetIntLiteral(0);
  2082.   nimIM.SetBuddyIconFlag(selectedItem, checksumBIres, csliteral);
  2083.   
  2084.   var nimBuddy = aimBuddyManager();
  2085.   nimBuddy.SetHasBuddyIconFlag(selectedItem, false);
  2086.   nimBuddy.SetBuddyIconRejectFlag(selectedItem, false);
  2087.   
  2088.   clearBuddyIconImage();
  2089.  
  2090. }
  2091.  
  2092. function clearAllBuddyIcons()
  2093. {
  2094.   var userresponse;
  2095.   userresponse = confirm(getString("bi.clearall"));
  2096.   if (userresponse == false) 
  2097.     return;
  2098.  
  2099.   clearPersonalBuddyIcon();
  2100.   clearAllRemoteBuddyIcons();
  2101.   var nimIM = aimIM();
  2102.   nimIM.ClearAllBuddyIconFlags();
  2103.   clearBuddyIconImage();
  2104.  
  2105. }
  2106.  
  2107. /*clears all the remote buudies BI
  2108.   deletes the picture directory and creates an empty one ;-) */
  2109. function clearAllRemoteBuddyIcons()
  2110. {
  2111.   var pIAimSession = pIIMManager.QueryInterface(Components.interfaces.nsIAimSession);
  2112.   var pDir = pIAimSession.profileDir;
  2113.   var pictureDir = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  2114.   pictureDir.initWithPath(pDir.path);
  2115.   pictureDir.append("picture");
  2116.   if ((pictureDir.exists()) && (pictureDir.isDirectory())) {
  2117.     var fileslist = pictureDir.directoryEntries;
  2118.     while(fileslist.hasMoreElements()) {
  2119.       var nextfile = fileslist.getNext().QueryInterface(Components.interfaces.nsIFile);
  2120.       if (nextfile && !nextfile.isDirectory())
  2121.         nextfile.remove(false);
  2122.     }
  2123.   }
  2124. }
  2125.  
  2126.  
  2127. /*Clears the personal Buddy Icon from the profilr directory and in COOL */
  2128. function clearPersonalBuddyIcon()
  2129. {
  2130.   var biimage = document.getElementById("buddyIconImage");
  2131.   var pIAimSession = pIIMManager.QueryInterface(Components.interfaces.nsIAimSession);
  2132.   var pDir = pIAimSession.profileDir;
  2133.   var pictureDir = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  2134.   pictureDir.initWithPath(pDir.path);
  2135.   pictureDir.append("picture.gif");
  2136.   if (pictureDir.exists()) {
  2137.     //remove the image from the profile dir. clear the bi. send signal back to COOL.
  2138.     biimage.removeAttribute("src");
  2139.     pIAimSession.SetBuddyIcon(true);
  2140.     pictureDir.remove(false);
  2141.   }
  2142. }
  2143.  
  2144.  
  2145. function DisableBIElements()
  2146. {
  2147.   document.getElementById("buddyIconTree").setAttribute("hidden", "true");
  2148.   document.getElementById("btnBrowseFile").setAttribute("disabled", "true");
  2149.   document.getElementById("btnClear").setAttribute("disabled", "true");
  2150.   document.getElementById("btnClearAll").setAttribute("disabled", "true");
  2151.   document.getElementById("acceptFromUsers").setAttribute("disabled", "true");
  2152.   document.getElementById("buddyKnockKnock").setAttribute("disabled", "true");
  2153.   document.getElementById("neverAccept").setAttribute("disabled", "true");
  2154.   document.getElementById("neverDisplay").setAttribute("disabled", "true");
  2155. }
  2156.  
  2157. function changeKnockKnock()
  2158. {
  2159.   var displayBI = document.getElementById("displayBI").value;
  2160.   var kk = document.getElementById("buddyKnockKnock");
  2161.   if(displayBI == "0")
  2162.     kk.removeAttribute("disabled");
  2163.   else
  2164.     kk.setAttribute("disabled", "true");
  2165. }
  2166.  
  2167. function onBISelectionChange()
  2168. {
  2169.   var buddyTree = document.getElementById("buddyIconTree");
  2170.   var startIndex = {};
  2171.   var endIndex = {};
  2172.   buddyTree.treeBoxObject.selection.getRangeAt(0, startIndex, endIndex);
  2173.   var sindex = startIndex.value;
  2174.   var eindex = endIndex.value;
  2175.   var view = buddyTree.treeBoxObject.view;
  2176.   var level = view.getLevel(sindex);
  2177.   var selectedItem = view.getCellText(sindex, "ListSetupCol");
  2178.   
  2179.  
  2180.   if ((level == 0) && (sindex > 0)) {
  2181.     //a group is selected. disable the buttons and clear the image.
  2182.     document.getElementById("btnBrowseFile").setAttribute("disabled", "true");
  2183.     document.getElementById("btnClear").setAttribute("disabled", "true");
  2184.     clearBuddyIconImage();
  2185.     return;
  2186.   }
  2187.   else {
  2188.     document.getElementById("btnBrowseFile").setAttribute("disabled", "false");
  2189.     document.getElementById("btnClear").setAttribute("disabled", "false");
  2190.   }
  2191.  
  2192.   if (sindex == 0) {
  2193.     LoadPersonalBuddyIcon();
  2194.     return;
  2195.   }
  2196.  
  2197.   if ((sindex >0) && (level != 0)) {
  2198.     //load the remote buddies buddy icon
  2199.     LoadRemoteBuddyBuddyIcon(selectedItem);
  2200.   }
  2201.  
  2202. }
  2203.  
  2204.  
  2205. /* As the name implies, this guy loads the buddy Icon of the remote buddy from the picture directory*/
  2206. function LoadRemoteBuddyBuddyIcon(buddyname)
  2207. {
  2208.   var pIAimSession = pIIMManager.QueryInterface(Components.interfaces.nsIAimSession);
  2209.   var pDir = pIAimSession.profileDir;
  2210.   
  2211.   //set the image to current picture.gif
  2212.   var pictureDir = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  2213.   pictureDir.initWithPath(pDir.path);
  2214.   pictureDir.append("picture");
  2215.   if(!pictureDir.exists()) {
  2216.     return;
  2217.   }
  2218.   pictureDir.append(buddyname + ".gif");
  2219.   if (!pictureDir.exists()) {
  2220.     clearBuddyIconImage();
  2221.     return;
  2222.   }
  2223.  
  2224.   var ioService = GetIOService();
  2225.   var tfileurl1 = ioService.getURLSpecFromFile(pictureDir);
  2226.   //avoid loading from cache
  2227.   var currentTime = new Date().getTime();
  2228.   var biimage = document.getElementById("buddyIconImage");
  2229.   biimage.setAttribute("src", tfileurl1+"?foobar="+currentTime);
  2230.  
  2231.   return;
  2232. }
  2233.  
  2234. /*This just clears the image from the pref panel. */
  2235. function clearBuddyIconImage() {
  2236.   var biimage = document.getElementById("buddyIconImage");
  2237.   biimage.removeAttribute("src");
  2238.   return;
  2239. }
  2240.  
  2241. /*This loads the personal Buddy Icon from the profile directory*/
  2242. function LoadPersonalBuddyIcon() {
  2243.   var biimage = document.getElementById("buddyIconImage");
  2244.   var pIAimSession = pIIMManager.QueryInterface(Components.interfaces.nsIAimSession);
  2245.   var pDir = pIAimSession.profileDir;
  2246.   
  2247.   //set the image to current picture.gif
  2248.   var pictureDir = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  2249.   pictureDir.initWithPath(pDir.path);
  2250.   pictureDir.append("picture.gif");
  2251.   if (pictureDir.exists()) {
  2252.     var ioService = GetIOService();
  2253.     var tfileurl1 = ioService.getURLSpecFromFile(pictureDir);
  2254.     //avoid loading from cache
  2255.     var currentTime = new Date().getTime();
  2256.     biimage.setAttribute("src", tfileurl1+"?foobar="+currentTime);     
  2257.   }
  2258.   else {
  2259.     clearBuddyIconImage();
  2260.   }
  2261.   return;
  2262. }
  2263.  
  2264.  
  2265. function DisableAwayUI()
  2266. {
  2267.         var el = document.getElementById("buttonAddMess");
  2268.         if ( el )
  2269.             el.setAttribute( "disabled", "true" );
  2270.         el = document.getElementById("buttonEditMess");
  2271.         if ( el )
  2272.             el.setAttribute( "disabled", "true" );
  2273.         el = document.getElementById("buttonRemoveMess");
  2274.         if ( el )
  2275.             el.setAttribute( "disabled", "true" );
  2276.         el = document.getElementById("AwayMessages");
  2277.         if ( el )
  2278.             el.setAttribute( "disabled", "true" );
  2279. }
  2280.  
  2281. function DiscardAwayChanges()
  2282. {
  2283.  
  2284.     var IMServiceClass = Components.classes['@netscape.com/aim/IMManager;1'];
  2285.     var pIIMManager  = IMServiceClass.getService(Components.interfaces.nsIIMManager);
  2286.     var pIAimString = pIIMManager.QueryInterface(Components.interfaces.nsIStringBundle);
  2287.     
  2288.     if ( pIAimString == undefined || pIAimString == null )
  2289.         return;
  2290.  
  2291.     var str = pIAimString.GetStringFromName( "away.exitmsg" );
  2292.     if (str == undefined || str ==null)
  2293.         return;
  2294.     
  2295.     alert( str );
  2296. }
  2297.  
  2298. function boottoggle(value)
  2299. {
  2300.   parent.isBootEnabled = value;
  2301. }
  2302.  
  2303. function instantMessageOnOk()
  2304. {
  2305.   var winhooksService = Components.classes["@mozilla.org/winhooks;1"].getService(Components.interfaces.nsIWindowsHooks);
  2306.   if (winhooksService) {
  2307.     if (parent.isBootEnabled)
  2308.       winhooksService.startupAddOption("-aim");
  2309.     else
  2310.       winhooksService.startupRemoveOption("-aim");
  2311.   }
  2312. }
  2313.  
  2314. function instantMessageOnload()
  2315. {
  2316.   var todayhide = aimPrefsManager().GetBoolPref("aim.internal.hidetoday", null, false);
  2317.   if (todayhide)
  2318.   {
  2319.     document.getElementById("today").setAttribute("style", "display: none" );
  2320.   }
  2321.   if (navigator.platform != "Win32")
  2322.   {
  2323.     document.getElementById("boot").setAttribute("hidden", "true");
  2324.     // If all the elements in the Sign On group are removed, get ride of the groupbox
  2325.     // Otherwise we'll show an empty groupbox!
  2326.     if (todayhide)
  2327.     {
  2328.       document.getElementById("signongroup").setAttribute("style", "display: none" );
  2329.     }
  2330.     return;
  2331.   }
  2332.   if (!parent.hPrefWindow)
  2333.   {
  2334.     setTimeout("instantMessageOnload()", 1);
  2335.     return;
  2336.   }
  2337.   parent.hPrefWindow.registerOKCallbackFunc(instantMessageOnOk);
  2338.   if (!aimSession().CheckConflictRunKey())
  2339.   {
  2340.     var winhooksService = Components.classes["@mozilla.org/winhooks;1"].getService(Components.interfaces.nsIWindowsHooks);
  2341.     if (winhooksService) {
  2342.       parent.isBootEnabled = winhooksService.isOptionEnabled("-aim");
  2343.       document.getElementById("boot").checked = parent.isBootEnabled;
  2344.     }
  2345.   } 
  2346.   else
  2347.     document.getElementById("boot").setAttribute("disabled", "true");
  2348. }
  2349.  
  2350.